/** @description 五行 */
const ELEMENT = {
  金: 'gold',
  木: 'wood',
  水: 'water',
  火: 'fire',
  土: 'earth',
}

/** @description 类型 */
const TYPE = {
  生灵: 'live',
  法术: 'magic',
  装备: 'equip',
}
/** @description 类别 */
const CATEGORY: Record<Wx.Card.Type, { [K in Wx.Card.Category]?: string }> = {
  生灵: {
    佛门: 'FO_MEN',
    鬼吏: 'GUI_LI',
    雷神: 'LEI_SHEN',
    散仙: 'SAN_XIAN',
    神官: 'SHEN_GUAN',
    神兽: 'SHEN_SHOU',
    水族: 'SHUI_ZU',
    天将: 'TIAN_JIANG',
    天仙: 'TIAN_XIAN',
    妖怪: 'YAO_GUAI',
    妖仙: 'YAO_XIAN',
    异灵: 'YI_LING',
    异人: 'YI_REN',
    英魂: 'YING_HUN',
  },
  法术: {
    法术: 'FA_SHU',
    连锁法术: 'LIAN_SUO_FA_SHU',
    触发法术: 'CHU_FA_FA_SHU',
  },
  装备: {
    主角装备: 'ZHU_JUE_ZHUANG_BEI',
    生灵装备: 'SHENG_LING_ZHUANG_BEI',
  },
}
/** @description 所有官方类别 */
const OfficialCategory = new Set(
  Object.values(CATEGORY)
    .map((types) => Object.keys(types))
    .flat(),
)
/** @description 数值 */
const SKILL_CONSUME = {
  '0': 'zero',
  '1': 'one',
  '2': 'two',
  '3': 'three',
  '4': 'four',
  '5': 'five',
  '6': 'six',
  '7': 'seven',
  '8': 'eight',
  '?': 'unknown',
}
/** @description 品阶 */
const RANK: Record<Wx.Card.Rank, string> = {
  凡: 'laic',
  地: 'earth',
  天: 'sky',
}
/** @description 系列 */
const SERIES: Record<Wx.Card.Series, string> = {
  开天: 'KAI_TIAN',
  御龙: 'YU_LONG',
  碎云: 'SUI_YUN',
  补天: 'BU_TIAN',
  灵犀: 'LIN_XI',
  仙缘: 'XIAN_YUAN',
  兰因: 'LAN_YIN',
  万象: 'WAN_XIANG',
  试玩: 'SHI_WAN',
}
export const rankNames = (): Record<string, string> => {
  return Object.entries(RANK).reduce(
    (obj, [key, value]) => {
      obj[key] = value
      return obj
    },
    {} as Record<string, string>,
  )
}
export const grayRankNames = (): Record<string, string> => {
  return Object.entries(RANK).reduce(
    (obj, [key, value]) => {
      obj[key] = `${value}_gray`
      return obj
    },
    {} as Record<string, string>,
  )
}
// 卡牌类型
export const nameType = (data: Wx.Card.Param): string => {
  return `${TYPE[data.type!]}`
}
// 卡牌系列和稀有度
export const nameSeries = (data: Wx.Card.Param): string => {
  return `${SERIES[data.series!]}_${RANK[data.rank!]}`
}
// 卡牌类别
export const nameCategory = (data: Wx.Card.Param): string => {
  return `${CATEGORY[data.type!][data.category!]}`
}
// 判断是否为官方类别
export const isOfficialCategory = (data: Wx.Card.Param): boolean => {
  return Boolean(CATEGORY[data.type!][data.category!])
}
// 卡牌五行
export const nameElement = (data: Wx.Card.Param, index: number): string => {
  return `${ELEMENT[data.element!]}_${index}`
}
// 卡牌卡图
export const nameCard = (data: Wx.Card.Data): string => {
  return `/sprite/card/${ELEMENT[data.element]}/${data.id}.png`
}
// DIY卡牌卡图
export const nameDiyCard = async (data: Wx.Card.Data): Promise<string> => {
  return await window.api.getDiyAsset(data.author!, data.id)
}
// 卡牌技能消耗
export const nameSkillConsume = (data: Wx.Card.Param): string => {
  return `${SKILL_CONSUME[data.skillConsume!]}`
}

export { ELEMENT, TYPE, CATEGORY, SKILL_CONSUME, RANK, SERIES, OfficialCategory }
